package algorithm.linkedlist;

import algorithm.model.ListNode;

/**
 * 83. Remove Duplicates from Sorted List
 * leetcode : https://leetcode.com/problems/remove-duplicates-from-sorted-list/
 * Difficulty : Easy
 * @Author Antony
 * @Since 2018/11/15 19:33
 */
public class RemoveDuplicatesFromSortedList {

    public static void main(String[] args) {
        ListNode node = ListNode.initDate(new int[]{1,1,2,2,2,3,3,4});
        System.out.println(node.nodeString());
        deleteDuplicates(node);
        System.out.println(node.nodeString());

    }

    /**
     * leetcode : 0ms - beats 100.0%
     * @param head
     * @return
     */
    public static ListNode deleteDuplicates(ListNode head) {
        ListNode curr = head;
        while(curr != null && curr.next != null){
            if(curr.val == curr.next.val){
                curr.next = curr.next.next;
            }else{
                curr = curr.next;
            }
        }
        return head;
    }
}
